package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.domain.DateAndID;
import com.ruoyi.system.domain.SysOrder;
import com.ruoyi.system.mapper.SysOrderMapper;
import com.ruoyi.system.service.ISysOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * 订单Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-05-21
 */
@Service
public class SysOrderServiceImpl implements ISysOrderService
{
    @Autowired
    private SysOrderMapper sysOrderMapper;

    @Override
    public BigDecimal totalMoney(BigDecimal bigDecimal, Long num) {
        BigDecimal totalMoney = bigDecimal.multiply(new BigDecimal(num));

        return totalMoney;
    }

    @Override
    public Integer selectOrderCount1(DateAndID dateAndID) {
        return sysOrderMapper.selectOrderCount1(dateAndID);
    }

    @Override
    public List<SysOrder> selectOrderMonth(DateAndID dateAndID) {
        return sysOrderMapper.selectOrderMonth(dateAndID);
    }

    @Override
    public Integer selectOrderCount(Long id) {
        return sysOrderMapper.selectOrderCount(id);
    }

    /**
     * 根据公司ID 计算公司账单总金额
     * @param id 公司id
     * @return 总金额
     */
    @Override
    public Float selectOrderSum(Long id) {
        return sysOrderMapper.selectOrderSum(id);
    }

    /**
     * 查询订单
     * 
     * @param id 订单ID
     * @return 订单
     */
    @Override
    public SysOrder selectSysOrderById(Long id)
    {
        return sysOrderMapper.selectSysOrderById(id);
    }

    /**
     * 查询订单列表
     * 
     * @param sysOrder 订单
     * @return 订单
     */
    @Override
    public List<SysOrder> selectSysOrderList(SysOrder sysOrder)
    {
        return sysOrderMapper.selectSysOrderList(sysOrder);
    }

    /**
     * 新增订单
     * 
     * @param sysOrder 订单
     * @return 结果
     */
    @Override
    public int insertSysOrder(SysOrder sysOrder)
    {

        sysOrder.setCreateTime(DateUtils.getNowDate());
        sysOrder.setCreateBy(ShiroUtils.getLoginName());
        return sysOrderMapper.insertSysOrder(sysOrder);
    }

    /**
     * 修改订单
     * 
     * @param sysOrder 订单
     * @return 结果
     */
    @Override
    public int updateSysOrder(SysOrder sysOrder)
    {
        sysOrder.setUpdateTime(DateUtils.getNowDate());
        sysOrder.setUpdateBy(ShiroUtils.getLoginName());
        return sysOrderMapper.updateSysOrder(sysOrder);
    }

    /**
     * 删除订单对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSysOrderByIds(String ids)
    {
        return sysOrderMapper.deleteSysOrderByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除订单信息
     * 
     * @param id 订单ID
     * @return 结果
     */
    @Override
    public int deleteSysOrderById(Long id)
    {
        return sysOrderMapper.deleteSysOrderById(id);
    }

    @Override
    public List<SysOrder> selectOrderLastMonth(DateAndID dateAndID) {
        return sysOrderMapper.selectOrderLastMonth(dateAndID);
    }

    @Override
    public List<SysOrder> selectOrderOfDay(String date1, String date2) {
        return sysOrderMapper.selectOrderOfDay(date1,date2);
    }
}
